package com.rongxun.hbwallet.ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.VirtualLayoutManager;
import com.rongxun.hbwallet.R;
import com.rongxun.hbwallet.model.bean.CandyTask;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 创建者     庄丰泽
 * 创建时间   2018/5/29 18:36
 * 描述	      更多任务
 */

public class TaskContentAdapter extends DelegateAdapter.Adapter<TaskContentAdapter.ViewHolder> {
    private Context      mContext;
    private LayoutHelper mHelper;
    private int mCount = 1;
    private VirtualLayoutManager.LayoutParams mParams;
    List<CandyTask> mRankListBeans = new ArrayList<>();

    public TaskContentAdapter(Context context, LayoutHelper helper, List<CandyTask> mDatas) {
        this(context, helper, mDatas, new VirtualLayoutManager.LayoutParams(VirtualLayoutManager.LayoutParams.MATCH_PARENT, VirtualLayoutManager.LayoutParams.WRAP_CONTENT));
    }

    public TaskContentAdapter(Context context, LayoutHelper helper, List<CandyTask> mDatas, VirtualLayoutManager.LayoutParams params) {
        mContext = context;
        mHelper = helper;
        mCount = mDatas.size();
        mRankListBeans = mDatas;
        mParams = params;

    }

    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return mHelper;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_moretasks_content, parent, false);

        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

    }

    @Override
    protected void onBindViewHolderWithOffset(ViewHolder holder, int position, int offsetTotal) {
        super.onBindViewHolderWithOffset(holder, position, offsetTotal);

        holder.mTitle.setText(mRankListBeans.get(position).getEvent());

        holder.mNum.setText(String.format(mContext.getString(R.string.candy_sum), mRankListBeans.get(position).getCandyNum()));


        if (mRankListBeans.get(position).getTodayLimit() == null) {
            holder.mState.setTextColor(Color.parseColor("#FF5C5D"));
            holder.mState.setText(String.format(mContext.getString(R.string.todayNum), mRankListBeans.get(position).getTodayNum()));
            holder.mIvState.setVisibility(View.GONE);
        } else if (Integer.parseInt(mRankListBeans.get(position).getTodayLimit()) == mRankListBeans.get(position).getTodayNum()) {

            holder.mState.setTextColor(Color.GRAY);
            holder.mIvState.setVisibility(View.VISIBLE);
            holder.mState.setText(mContext.getString(R.string.completed));
        } else {
            holder.mState.setTextColor(Color.parseColor("#FF5C5D"));
            holder.mIvState.setVisibility(View.GONE);
            holder.mState.setText(mContext.getString(R.string.not_finished));
        }


    }

    @Override
    public int getItemCount() {
        if (mRankListBeans != null) {
            return mRankListBeans.size();
        }
        return 0;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.inviting_friends)
        TextView mTitle;
        @BindView(R.id.inviting_tv_sum)
        TextView mNum;
        @BindView(R.id.inviting_tv_state)
        TextView mState;
        @BindView(R.id.inviting_iv_state)
        ImageView mIvState;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
